<?php
class Application_Model_Department extends Application_Model_Db_Db
{
    /**
     * get all depts
     * @return array
     */
    public function getAllDepartments() {
		$sql = "SELECT
		            `dept`.`id`,
		            `dept`.`category_name` AS `department_name`,
		            `dept`.`alias`
		        FROM `category` AS `dept`
		        INNER JOIN `category_type`
		            ON `dept`.`type_id` = `category_type`.`id`
		        WHERE `category_type`.`type` = 'department'";
		return $this->_db->fetchAll($sql);
	}

	/**
     * get department title name by category alias
     * @param $alias
     * @return string
     */
    public function getDepartmentTitleByAliasAndDepartmentId($alias, $departmentId=0) {
        $sql = "SELECT
                    `category`.`category_name`
                FROM `category`
                WHERE 
                    1
                    AND `category`.`alias` = ?
                    AND `category`.`department_id` = ?";
        return $this->_db->fetchOne($sql, array($alias, $departmentId));
    }    
}